package com.dmxh.controller;

import com.dmxh.params.QueryParams;
import com.dmxh.result.PageList;
import com.dmxh.result.Result;
import com.dmxh.service.ContentService;
import com.dmxh.vo.ContentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/content")
public class ContentController {

    @Autowired
    private ContentService contentService;

    @GetMapping("/queryAllContent")
    public Result queryAllContent() {
        Map<String, Object> map = contentService.queryAllContent();
        return Result.ok().setData(map);
    }

    @PostMapping("/queryPage")
    public Result<PageList<ContentVo>> queryPage(@RequestBody QueryParams queryParams) {
        PageList<ContentVo> pageList = contentService.queryPage(queryParams);
        return Result.ok().setData(pageList);
    }

    @PostMapping("/save")
    public Result save(@RequestBody ContentVo contentVo) {
        if (contentVo.getId() == null) {
            contentService.addInfo(contentVo);
        } else {
            contentService.updateInfo(contentVo);
        }
        return Result.ok();
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id")long id) {
        contentService.deleteById(id);
        return Result.ok();
    }

    @PatchMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody Integer[]ids) {
        contentService.deleteBatch(ids);
        return Result.ok();
    }
}
